package kz.kstu.scantest.business.entity.security;

import kz.kstu.scantest.business.entity.CommonEntityConstant;
import kz.kstu.scantest.business.entity.Identifiable;

import javax.persistence.*;

/**
 * @author Filipp_Stankevich
 *         created: 27.09.11 19:48
 */
@NamedQueries({
        @NamedQuery(name = CommonEntityConstant.FIND_ACCOUNT_BY_LOGIN_AND_PASSWORD,
                query = "select a from Account a where a.login = :login and a.password = :password "),
         @NamedQuery(name = CommonEntityConstant.UPDATE_PASSWORD_BY_ACCOUNT_ID,
                query = "update Account a set a.password = :password where a.id = :id")

})

@Entity
@Table(name = "ACCOUNT")
public class Account implements Identifiable {

    private Long id;
    private String login;
    private String password;
    private boolean isBlocked;
    private RoleEnum roleEnum;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "LOGIN", unique = true, nullable = false)
    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    @Column(name = "PASSWORD", nullable = false)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column(name = "IS_BLOCKED")
    public boolean isBlocked() {
        return isBlocked;
    }

    public void setBlocked(boolean blocked) {
        isBlocked = blocked;
    }

    @Enumerated
    @Column(name = "ROLE_ID")
    public RoleEnum getRoleEnum() {
        return roleEnum;
    }

    public void setRoleEnum(RoleEnum roleEnum) {
        this.roleEnum = roleEnum;
    }
}
